package com.example.provider.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: qilongxin
 * @date: 2021/11/9 17:18
 */
@Configuration
public class RabbitmqTopicConfig {

    private final static String FIRST_KEY = "topic.man";

    private final static String SECOND_KEY = "topic.woman";

    @Bean
    public Queue firstQueue() {
        return new Queue(RabbitmqTopicConfig.FIRST_KEY);
    }

    @Bean
    public Queue secondQueue() {
        return new Queue(RabbitmqTopicConfig.SECOND_KEY);
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("topicExchange");
    }

    @Bean
    public Binding firstBinding() {
        return BindingBuilder.bind(firstQueue()).to(topicExchange()).with(FIRST_KEY);
    }

    @Bean
    public Binding secondBinding() {
        return BindingBuilder.bind(secondQueue()).to(topicExchange()).with("topic.#");
    }

}
